//
//  LongArray.m
//  iHedron
//
//  Created by George Radev on 2011-08-03.
//  Copyright 2011 I Me Mine. All rights reserved.
//

#import "LongArray.h"


@implementation LongArray

-(id)init {
	self = [super init];
	size = 16;
	count = 0;
	list = (long*) malloc(sizeof(long) * size);
	return self;
}

-(void) dealloc {
	free(list);
    [super dealloc];
}

-(void)add:(long) l {
	if (count >= size) {
		size += 32;
		list = (long*) realloc(list, sizeof(long) * size);
	}
	list[count] = l;
	count++;
}

-(long)get: (long) pos {
	return ( pos >= 0 && pos < count) ? list[pos] : 0;
}

-(void)set: (long) pos value:(long) l {
	if ( pos >= 0 && pos < count) {
		list[pos]  = l;
	}
}

-(long)length {
	return count;
}

-(void)sort {
	for (long i = 0; i < count - 1; i++) {
		for (long j = i + 1; j < count; j++) {
			if (list[i] > list[j]) {
				long l = list[i];
				list[i] = list[j];
				list[j] = l;
			}
		}
	}
}

@end
